package com.live.spaces.shanboli;


import javax.xml.parsers.*;
import org.w3c.dom.*;

public class ReadXML {
	static Document document;
	String nickName = null;

	private boolean validating;

	public ReadXML() {
	}

	public String toRead() {
//		Vector title = new Vector();
//		Vector content = new Vector();
		String myStr = new String();
		String nickName = null;
	
		try {
			DocumentBuilderFactory factory = DocumentBuilderFactory
					.newInstance();
			factory.setValidating(validating);
			DocumentBuilder builder = factory.newDocumentBuilder();
			
			document = builder.parse(getClass().getResourceAsStream("./nickname.xml"));
			document.getDocumentElement().normalize();
			Node node = document.getFirstChild();
			NodeList list = node.getChildNodes();
			for (int i = 0; i < list.getLength(); i++) {
				Node nodeitm = list.item(i);
				if (nodeitm.getNodeName().equals("NickName")) {
					myStr = nodeitm.getFirstChild().getNodeValue();
					nickName = myStr;// getFirstChild()
				}
				// if (nodeitm.getNodeName().equals("Content")) {
				// myStr = nodeitm.getFirstChild().getNodeValue();
				// content.addElement(myStr);
				// }
			}
		} catch (Exception exp) {
			exp.printStackTrace();
			return null;
		}
//		Vector all = new Vector();
//		all.add(title);
//		all.add(content);
		return nickName;
	}

	public static void main(String[] args) {
		
		ReadXML my = new ReadXML();
		String s = my.toRead();

		System.out.println(s);
		
		// for (int i = 0; i < A.size(); i++) {
		// System.out.println(A.elementAt(i));
		// }
	}
}
